package com.calm.cdemo.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.calm.cdemo.R;

/**
 * Create by Calm
 * 2020/1/9 11:00
 * 基类Activity
 */
public abstract class BaseActivity extends AppCompatActivity {
    protected final String CLASS = this.getClass().getSimpleName();
    protected Activity mActivity;
    protected abstract void init();
    protected abstract @LayoutRes int getLayoutId();
    private TextView tvTitle;
    private ImageView ivBack;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.baseactivity);
        mActivity = this;
        int layoutId = getLayoutId();
        if (layoutId > 0){
            View chidView = LayoutInflater.from(this).inflate(layoutId,null);
            FrameLayout content = findViewById(R.id.base_fl_content);
            content.addView(chidView);
        }
        ivBack = findViewById(R.id.base_iv_back);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvTitle = findViewById(R.id.base_tv_title);
        init();
    }
    protected void setTitle(String title){
        tvTitle.setText(title);
    }
    protected void setTitleVisiable(int visiable){
        tvTitle.setVisibility(visiable);
    }
    protected void setTitle(String title,int visiable){
        tvTitle.setText(title);
        tvTitle.setVisibility(visiable);
    }
    protected void setBackVisiable(int visiable){
        ivBack.setVisibility(visiable);
    }
    protected void setBackListener(View.OnClickListener listener){
        ivBack.setOnClickListener(listener);
    }
}
